package com.bf.electroplating.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bf.electroplating.pojo.dto.IdDTO;
import com.bf.electroplating.pojo.dto.facility.ComEnvironmentallyFacilityDTO;
import com.bf.electroplating.pojo.vo.ResultVO;
import com.bf.electroplating.pojo.vo.facility.ComEnvironmentallyFacilityListVO;
import com.bf.electroplating.pojo.vo.facility.ComEnvironmentallyFacilityVO;
import com.bf.electroplating.service.ComEnvironmentallyFacilityService;
import com.bf.electroplating.util.idempotent.Idempotent;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/environmentallyFacility")
@Tag(name = "环保设施信息", description = "环保设施信息管理")
public class ComEnvironmentallyFacilityController {

    @Autowired
    private ComEnvironmentallyFacilityService facilityService;

    @GetMapping("/list")
    @Operation(summary = "获取环保设施列表", description = "获取全部环保设施信息列表")
    public ResultVO<List<ComEnvironmentallyFacilityListVO>> getFacilityList() {
        return ResultVO.ok(facilityService.getFacilityList());
    }

    @PostMapping("/list")
    @Operation(summary = "获取环保设施列表", description = "分页获取环保设施信息列表")
    public ResultVO<Page<ComEnvironmentallyFacilityVO>> getFacilityList(@RequestBody ComEnvironmentallyFacilityDTO dto) {
        return ResultVO.ok(facilityService.getFacilityList(dto));
    }

    @PostMapping("/getFacilityById")
    @Operation(summary = "获取环保设施详情", description = "根据ID获取环保设施详细信息")
    public ResultVO<ComEnvironmentallyFacilityVO> getFacilityById(@RequestBody IdDTO id) {
        return ResultVO.ok(facilityService.getFacilityById(id.getId()));
    }

    @Idempotent
    @PostMapping("/saveFacility")
    @Operation(summary = "新增环保设施", description = "新增环保设施信息")
    public ResultVO<Boolean> saveFacility(@RequestBody ComEnvironmentallyFacilityVO vo) {
        return ResultVO.ok(facilityService.saveFacility(vo), "保存成功");
    }

    @Idempotent
    @PostMapping("/updateFacility")
    @Operation(summary = "修改环保设施", description = "修改环保设施信息")
    public ResultVO<Boolean> updateFacility(@RequestBody ComEnvironmentallyFacilityVO vo) {
        return ResultVO.ok(facilityService.updateFacility(vo), "保存成功");
    }

    @PostMapping("/deleteFacility")
    @Operation(summary = "删除环保设施", description = "根据ID删除环保设施信息")
    public ResultVO<Boolean> deleteFacility(@RequestBody IdDTO id) {
        return ResultVO.ok(facilityService.deleteFacility(id.getId()), "删除成功");
    }

    @PostMapping("/batch")
    @Operation(summary = "批量删除环保设施", description = "批量删除环保设施信息")
    public ResultVO<Boolean> batchDeleteFacility(@RequestBody List<String> ids) {
        return ResultVO.ok(facilityService.batchDeleteFacility(ids), "删除成功");
    }
} 